package com.example.sys.ai.listener;


import com.example.core.utils.StringUtils;
import com.example.sys.ai.dto.BankCard;
import com.example.sys.ai.service.SysAiService;
import com.example.sys.attachment.po.SysAttachment;
import com.example.sys.attachment.service.SysAttachmentServiceImpl;
import com.example.sys.attachment.service.SysAttachmentUpLoadListener;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/***
 * 银行卡的OCR识别
 */
@Service
public class SysAttachmentUpLoadBankCardListener implements SysAttachmentUpLoadListener {

    private static final String BANK_CARD = "bankCard";

    @Resource
    private SysAiService sysAiService;

    @Override
    public void onListener(HttpServletRequest request, SysAttachment sysAttachment, byte[] bytes) throws Exception {
        if (StringUtils.isNotEmpty(request.getParameter(SysAttachmentServiceImpl.OCRKEY)) && request.getParameter(SysAttachmentServiceImpl.OCRKEY).equalsIgnoreCase(BANK_CARD)) {
            BankCard bankCard = this.sysAiService.bankCard(bytes);
            if (bankCard != null) {
                sysAttachment.setOcrObj(bankCard);
            }
        }
    }
}
